package org.example.Volatile;

import java.util.concurrent.TimeUnit;

public class Test01_Volatile {
    //对比有无volatile关键字，volatile关键字能保证线程间的可见性，即一个线程修改了共享变量的值，其他线程能立即看到修改后的最新值。
    volatile boolean running = true;
    //boolean running = true;
    void m() {
        System.out.println("m  start");
        while (running) {

        }
        System.out.println("m end!");
    }

    public static void main(String[] args) {

        Test01_Volatile t = new Test01_Volatile();
        new Thread(t::m,"t1").start();
        try{
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t.running = false;
    }
}
